<?php

namespace app\api\controller;
use app\common\controller\Api;
use app\admin\model\Teachers as Teacher;

/**
 * 小学教师活动领取
 */
class Teachers extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model;

    public function _initialize(){
        $this->model = new Teacher();
    }

  	public function index()
    {
        $row = $this->request->post();
        $Teacher = new Teacher();
        $result = $Teacher->allowField(true)->save($row);
        if ($result !== false) {
            $rows = $Teacher->get($Teacher->getLastInsID());
            $post = [
                'id'=>$rows->id,
                'name'=>$rows->name,
                'phone'=>$rows->phone,
                'address'=>$rows->shen_text.$rows->shi_text.$rows->xian_text.$rows->address,
                'text'=>$rows->version,
                'school'=>$rows->school,
                'type'=>$rows->type,
                'moban'=>'teachers',
            ];
            $response = \fast\Http::post('http://oa.fc62.com/index/Assistant/chant',$post);
            $this->success('添加成功');
        } else {
            $this->error('添加失败');
        }
    }

    public function tel($tel)
    {
        $Recruitto = new Teacher();
        if($Recruitto->where('phone','=',$tel)->find())
        {
            $this->error('手机号码重复，不可重复添加。');
        }
        $this->success('可以添加。');
    }




}
